﻿using Caliburn.Micro;
using CoProjectDF.Repository;
using CoProjectModel;
using Coproject.ViewModels;
using IdeaBlade.Application.Framework.Core.Authentication;
using IdeaBlade.Application.Framework.Core.DesignTimeSupport;
using IdeaBlade.Application.Framework.Core.Persistence;

namespace CoProjectDF.DesignTimeSupport
{
    /// <summary>
    /// The ViewModelLocator is used during design time to find a reference to the ViewModel with
    /// sample data.
    /// 
    /// The ViewModelLocator is loaded as a static resource in App.xaml
    /// 
    /// (See) &lt:designTimeSupport:ViewModelLocator x:Key="ViewModelLocator" /&gt:
    ///  </summary>
    public class ViewModelLocator : BaseDesignTimeViewModelLocator<CoProjectEntities>
    {
        //TODO: Add references to all ViewModels

        public AdminViewModel AdminViewModel
        {
            get
            {
                var rp = new UserRepository(EntityManagerProvider);
                var vm = new AdminViewModel(rp,
                                            new AuthenticationService<CoProjectEntities>(EntityManagerProvider.Manager));
                vm.Start();
                return vm;
            }
        }

        public LoggingViewModel LoggingViewModel
        {
            get
            {
                var vm = new LoggingViewModel();
                vm.Start();
                return vm;
            }
        }

        public ToDoItemViewModel ToDoItemViewModel
        {
            get
            {
                var ea = new EventAggregator();
                var rp = new ToDoItemRepository(EntityManagerProvider);
                var vm = new ToDoItemViewModel(ea, rp);
                vm.Start();
                return vm;
            }
        }

        public ToDoListsViewModel ToDoListsViewModel
        {
            get
            {
                var ea = new EventAggregator();
                var rp = new ToDoListRepository(EntityManagerProvider);
                var vm = new ToDoListsViewModel(ea, rp);
                vm.Start();
                return vm;
            }
        }

        protected override IEntityManagerProvider<CoProjectEntities> CreateEntityManagerProvider()
        {
            return new DesignTimeEntityManagerProvider(new SampleDataProvider(new SampleDataLoader()));
        }
    }
}